﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cndp.View
{
    public class Html
    {
        public static void create_result_page(Model.Event e, Model.Contest contest)
        {
            var mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var sw = new StreamWriter(mydocpath +  @"\result.html");
             
            sw.WriteLine("<!DOCTYPE html>");
            sw.WriteLine("<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">");
            sw.WriteLine("<head>");
            sw.WriteLine("  <meta charset=\"utf-8\" />");
            sw.WriteLine("  <title> Topplista </title>");
            sw.WriteLine("</head>");
            sw.WriteLine("<body>");
            
            sw.WriteLine("<h1> Topplista </h1>");
            sw.WriteLine("<table border=\"1\" style=\"width:100%\">");
            sw.WriteLine("  <tr>");
            sw.WriteLine("      <th> Position </th>");
            sw.WriteLine("      <th> Namn </th>");
            sw.WriteLine("      <th> Poängskillnad </th>");
            sw.WriteLine("      <th> Poäng </th>");
            sw.WriteLine("  </tr>");

            for (var i = 0; i < e.HighScore.Count; i++)
            {
                sw.WriteLine("  <tr>");
                sw.WriteLine("      <td>" + (i+1) + "</td>");
                sw.WriteLine("      <td>" + e.HighScore[i].Key.Name + "</td>");
                sw.WriteLine("      <td>" + (e.HighScore[0].Value - e.HighScore[i].Value) + "</td>");
                sw.WriteLine("      <td>" + e.HighScore[i].Value + "</td>");
                sw.WriteLine("  </tr>");
            }

            sw.WriteLine("</table>");

            if (e.CoupleBool)
            {
                sw.WriteLine("<p>Information om gren: " + e.Gender + ", " + e.JumpHeight + "meter, " + e.Bracket + ", Parhopp. </p>");
            }
            else
            {
                sw.WriteLine("<p>Information om gren: " + e.Gender + ", " + e.JumpHeight + "meter, " + e.Bracket + ", Singelhopp. </p>");
            }

            sw.WriteLine("<p>Information om tävling: " + contest.Name + ", " + contest.Location + ", " + contest.StartTime + ". </p>");

            sw.WriteLine("</body>");
            sw.WriteLine("</html>");

            sw.Close();
        }
    }
}
